package z_app_server

import (
	"git.oschina.net/cnjack/z_app_server/handle"
	"git.oschina.net/cnjack/z_app_server/model"
	"github.com/go-martini/martini"
	"github.com/martini-contrib/render"
	//"github.com/martini-contrib/throttle"
	//"time"
)

func Run() {
	m := martini.Classic()

	m.Use(render.Renderer(render.Options{
		Charset: "UTF-8",
	}))
	// m.Use(throttle.Policy(&throttle.Quota{
	// 	Limit:  1,
	// 	Within: time.Second / 10,
	// }))
	m.Use(handle.AllowOriginHandle)

	m.Any("/user/login", handle.LoginHandle)
	m.Any("/user/regist", handle.RegistHandle)
	m.Any("/user/autologin", handle.CheckUser, handle.AutologinHandle)

	m.Any("/message/get", handle.CheckUser, handle.MessageGetHandle)
	m.Any("/message/post", handle.CheckUser, handle.MessageSendHandle)

	m.Any("/cp/set", handle.CheckUser, handle.SetCpHandle)
	m.Any("/cp/get", handle.CheckUser, handle.GetCpHandle)
	model.NewEngine()
	m.RunOnAddr(":8081")
}
